
/*
 * Copyright 2002-2022 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/*
 *版权所有2002-2022原作者。
 *
 *根据Apache许可证2.0版（“许可证”）获得许可；
 *除非符合许可证，否则不得使用此文件。
 *您可以在以下地址获取许可证副本：
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 *除非适用法律要求或书面同意，软件
 *根据许可证分发的内容是按“原样”分发的，
 *无任何明示或暗示的保证或条件。
 *有关管理权限和
 *许可证下的限制。
 */

package org.springframework.beans;

import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.Introspector;

import org.springframework.core.Ordered;
import org.springframework.core.SpringProperties;
import org.springframework.lang.NonNull;

/**
 * {@link BeanInfoFactory} implementation that performs standard
 * {@link java.beans.Introspector} inspection.
 *
 * <p>To be configured via a {@code META-INF/spring.factories} file with the following content:
 * {@code org.springframework.beans.BeanInfoFactory=org.springframework.beans.StandardBeanInfoFactory}
 *
 * <p>Ordered at {@link Ordered#LOWEST_PRECEDENCE} to allow other user-defined
 * {@link BeanInfoFactory} types to take precedence.
 *
 * @author Juergen Hoeller
 * @since 6.0
 * @see ExtendedBeanInfoFactory
 * @see CachedIntrospectionResults
 * @see Introspector#getBeanInfo(Class)
 */
/**
 *执行标准的｛@link BeanInfoFactory｝实现
 *｛@link java.beans。Introspector｝检查。
 *
 *＜p＞通过具有以下内容的｛@code META-INF/spring.factors｝文件进行配置：
 *｛@code org.springframework.bean.BeanInfoFactory=org.springfframework.beans.StandardBeanInfoFactory｝
 *
 *＜p＞在｛@link Ordered#LOWEST_PRECDENCE｝处订购，以允许其他用户定义
 *｛@link BeanInfoFactory｝类型优先。
 *
 *@作者Juergen Hoeller
 *@自6.0起
 *@参见ExtendedBeanInfoFactory
 *@参见CachedIntrossectionResults
 *@参见Introspector#getBeanInfo（类）
 */
public class StandardBeanInfoFactory implements BeanInfoFactory, Ordered {

	/**
	 * System property that instructs Spring to use the {@link Introspector#IGNORE_ALL_BEANINFO}
	 * mode when calling the JavaBeans {@link Introspector}: "spring.beaninfo.ignore", with a
	 * value of "true" skipping the search for {@code BeanInfo} classes (typically for scenarios
	 * where no such classes are being defined for beans in the application in the first place).
	 * <p>The default is "false", considering all {@code BeanInfo} metadata classes, like for
	 * standard {@link Introspector#getBeanInfo(Class)} calls. Consider switching this flag to
	 * "true" if you experience repeated ClassLoader access for non-existing {@code BeanInfo}
	 * classes, in case such access is expensive on startup or on lazy loading.
	 * <p>Note that such an effect may also indicate a scenario where caching doesn't work
	 * effectively: Prefer an arrangement where the Spring jars live in the same ClassLoader
	 * as the application classes, which allows for clean caching along with the application's
	 * lifecycle in any case. For a web application, consider declaring a local
	 * {@link org.springframework.web.util.IntrospectorCleanupListener} in {@code web.xml}
	 * in case of a multi-ClassLoader layout, which will allow for effective caching as well.
	 * @see Introspector#getBeanInfo(Class, int)
	 */
	/**
	 *指示Spring使用｛@link Introspector#IGNORE_ALL_BEANINFO｝的系统属性
	 *当调用JavaBeans｛@link Introspector｝：“spring.beaninfo.ignore”时，使用
	 *值“true”，跳过搜索｛@code BeanInfo｝类（通常用于场景
	 *其中首先没有为应用程序中的bean定义此类类）。
	 *＜p＞考虑到所有｛@code BeanInfo｝元数据类，默认值为“false”，例如
	 *标准｛@link Introspector#getBeanInfo（Class）｝调用。考虑将此标志切换为
	 *如果您对不存在的｛@code BeanInfo｝重复访问ClassLoader，则返回“true”
	 *类，以防这种访问在启动或延迟加载时代价高昂。
	 *＜p＞注意，这种影响也可能表明缓存不起作用的情况
	 *有效：首选Spring jar位于同一ClassLoader中的安排
	 *作为应用程序类，它允许与应用程序的
	 *在任何情况下，生命周期。对于web应用程序，请考虑声明本地
	 *｛@code web.xml｝中的｛@link org.springframework.web.util.IntrospectorCleanupListener｝
	 *在多ClassLoader布局的情况下，这也将允许有效的缓存。
	 *@参见Introspector#getBeanInfo（类，int）
	 */
	public static final String IGNORE_BEANINFO_PROPERTY_NAME = "spring.beaninfo.ignore";

	private static final boolean shouldIntrospectorIgnoreBeaninfoClasses =
			SpringProperties.getFlag(IGNORE_BEANINFO_PROPERTY_NAME);


	@Override
	@NonNull
	public BeanInfo getBeanInfo(Class<?> beanClass) throws IntrospectionException {
		return (shouldIntrospectorIgnoreBeaninfoClasses ?
				Introspector.getBeanInfo(beanClass, Introspector.IGNORE_ALL_BEANINFO) :
				Introspector.getBeanInfo(beanClass));
	}

	@Override
	public int getOrder() {
		return Ordered.LOWEST_PRECEDENCE;
	}

}
